import request from '@/utils/request';
import { AxiosPromise } from 'axios';

/**
 * 查询物料清单的列表
 * @param query
 * @returns {*}
 */

export const listBom = (query?: BomVO): AxiosPromise<BomVO[]> => {
  return request({
    url: '/wms/bom/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询物料清单详细
 * @param id
 */
export const getBom = (id: string | number): AxiosPromise<BomVO> => {
  return request({
    url: '/wms/bom/' + id,
    method: 'get'
  });
};

/**
 * 新增物料清单
 * @param data
 */
export const addBom = (data: BomVO ) => {
  return request({
    url: '/wms/bom',
    method: 'post',
    data: data
  });
};

/**
 * 修改物料清单
 * @param data
 */
export const updateBom = (data: BomVO) => {
  return request({
    url: '/wms/bom',
    method: 'put',
    data: data
  });
};

/**
 * 删除物料清单
 * @param id
 */
export const delBom = (id: string | number | Array<string | number>) => {
  return request({
    url: '/wms/bom/' + id,
    method: 'delete'
  });
};

/**
 * 查询物料明细清单的列表
 * @param query
 * @returns {*}
 */
export const listBomLine = (query?: BomLineVO): AxiosPromise<BomLineVO[]> => {
  return request({
    url: '/wms/bom/line/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询物料清单明细详细
 * @param data
 */
export const getBomLine = (data:BomLineVO):AxiosPromise<BomLineVO> => {
  return request({
    url: '/wms/bom/line' ,
    method: 'get',
    params: data
  });
};

/**
 * 新增物料清单明细
 * @param data
 */
export const addBomLine = (data: BomLineVO ) => {
  return request({
    url: '/wms/bom/line',
    method: 'post',
    data: data
  });
};

/**
 * 修改物料清单
 * @param data
 */
export const updateBomLine = (data: BomLineVO) => {
  return request({
    url: '/wms/bom/line',
    method: 'put',
    data: data
  });
};


/**
 * 删除物料清单明细
 * @param id
 */
export const delBomLine = (data: BomLineVO):AxiosPromise<BomLineVO> => {
  return request({
    url: '/wms/bom/line',
    method: 'delete',
    data: data
  });
};

/**
 * 新增物料清单明细
 * @param data
 */
export const addBomProcess = (data: BomProcessVO ) => {
  return request({
    url: '/wms/bom/process',
    method: 'post',
    data: data
  });
};

/**
 * 修改物料清单
 * @param data
 */
export const updateBomProcess = (data: BomProcessVO) => {
  return request({
    url: '/wms/bom/process',
    method: 'put',
    data: data
  });
};


/**
 * 查询物品工序的列表
 * @param query
 * @returns {*}
 */
export const listBomProcess = (query?: BomProcessVO): AxiosPromise<BomProcessVO[]> => {
  return request({
    url: '/wms/bom/process/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询物品工序详细
 * @param data
 */
export const getBomProcess = (data:BomProcessVO):AxiosPromise<BomProcessVO> => {
  return request({
    url: '/wms/bom/process' ,
    method: 'get',
    params: data
  });
};

/**
 * 删除物品工序
 */
export const delBomProcess = (data: BomProcessVO):AxiosPromise<BomProcessVO> => {
  return request({
    url: '/wms/bom/process',
    method: 'delete',
    data:data
  });
};


export interface BomVO extends BaseEntity, PageQuery {

  id?: number;

  name?: string;

  productId?: number;

  costTime?: number;

  productName?: string;

  status?: string;

  remark?: string;

  bomLine?: BomLineVO[];

  bomProcess?: BomProcessVO[];
}

export interface BomLineVO extends BaseEntity {

  id?: number;

  productId?: number;
  productName?: string;

  parentId?: number;

  quantity?: number;

  status?: string;

  remark?: string;

  parentIds?:number[];

  childIds?:number[];

  children?: BomLineVO[];

  oldLine?: BomLineVO;

  bomName?: string;

}

export interface BomProcessVO extends BaseEntity, PageQuery {

  id?: number;

  processId?: string|number;

  processName?: string;

  sort?: number;

  equipmentId?: number;

  status?: string;

  children?: BomProcessVO[];

  remark?: string;

}



